using Furion.DistributedIDGenerator;
using Furion.JsonSerialization;
using Newtonsoft.Json;

namespace SB2.Application;

public class DynamicFunctionRepository : AppSugarRepository<DynamicFunction>
{
    public DynamicFunctionRepository(ISqlSugarClient context) : base(context)
    {

    }
    [UnitOfWork]
    public async Task<DynamicFunction> GetNewAsync()
    {
        var chart = new DynamicFunction { }.New();
        await base.InsertReturnBigIdentityAsync(chart);
        return chart;
    }
    /// <summary>
    /// 写入缓存数据
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public async Task<long> AddParam(DynamicFunctionParamAddDto obj)
    {
        var data = new Dictionary<string, object>();
        var id = BitConverter.ToInt64(IDGen.NextID().ToByteArray());
        data["id"] = id;
        data["content"] = obj.content;
        data["userid"] = obj.userid;
        data["createDate"] = DateTime.Now;
        // data["scm"] = "";
        await base.Context.Insertable(data).AS("systempdata").ExecuteCommandAsync();
        return id;
    }

}

public class DynamicFunctionParamAddDto
{
    public string content { get; set; }
    public long userid { get; set; }
    public string code { get; set; }
}

[SugarTable("dynamicFunction")]
public class DynamicFunction : EntityHasUser
{
    [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
    public long DynamicFunctionID { get; set; }
    [SugarColumn(ColumnDescription = "名称", IsNullable = false)]
    public string name { get; set; }
    [SugarColumn(ColumnDescription = "描述")]
    public string Content { get; set; }
    [SugarColumn(ColumnDescription = "文件路径", IsNullable = false)]
    public string FilePath { get; set; }
    [SugarColumn(ColumnDescription = "文件类型", IsNullable = false)]
    public string FileType { get; set; }
    public DynamicFunction New()
    {
        DynamicFunctionID = BitConverter.ToInt64(IDGen.NextID().ToByteArray());
        return this;
    }
}

public class DynamicFunctDto : DynamicFunction
{


}